using MoXAML.Infrastructure;
using EnvDTE;
using System.Globalization;

namespace MoXAML.Scrubber
{
    public class ScrubAllFilesCommand : ScrubberCommandBase
    {
        public ScrubAllFilesCommand()
            : base()
        {
            CommandName = "ScrubAllFiles";
            Caption = "Scrubber";

            ParentCommandBar.Add(CommandBarType.SolutionContextMenu);
        }

        public override void Execute()
        {
            base.Execute();
            ParseFile(Application.ActiveDocument.FullName);
        }

        private void FindXamlFiles(ProjectItems items)
        {
            foreach (ProjectItem pi in items)
            {
                if (pi.Name.EndsWith("xaml", true, CultureInfo.CurrentUICulture))
                {
                    ParseFile(pi.get_FileNames(0));
                }
                else if (pi != null && pi.ProjectItems.Count > 0)
                {
                    FindXamlFiles(pi.ProjectItems);
                }
            }
        }
    }
}
